$(function () {
    $("#productInfo_datagrid").datagrid({
        url: "/storages/list?state=5",
        fitColumns: true,
        fit: true,
        rownumbers: true,
        striped: true,
        singleSelect:true,
        columns: [[
            {field: 'ck', checkbox: true},
            {field: 'id', title: '编号', hidden: true, width: 100},
            {
                field: 'clients', title: '投保人', width: 100, formatter: function (value, row, index) {
                return value ? value.clientname : "";
            }
            },
            {field: 'numbers', title: '保险单号', width: 100, align: 'right'},
            {field: 'limits', title: '投保总额度', width: 100, align: 'right'},
            {field: 'durations', title: '保险时长', width: 100},
            {field: 'put', title: '申请日期', width: 100},
            {
                field: 'agencyInfos', title: '保险机构', width: 100, formatter: function (value, row, index) {
                return value ? "<p>"+value.name+"</p>" : "<p>有bug</p>";
            }
            }
        ]],
        pagination: true,
        toolbar: "#tb",

    });
    //初始化对话框
    $("#my_dialog").dialog({
        width: 600,
        height: 600,
        closed: true,
        buttons:"#bb"
    })
    //初始化对话框-end
})


//缴费
function add() {

    var row = $("#productInfo_datagrid").datagrid("getSelected");
    if (!row) {
        $.messager.alert('温馨提示', '亲,请先选中你要查的数据');
        return;
    }
    $("#my_productInfos").datagrid({
        url: "/storages/list?state=5",
        fitColumns: true,
        rownumbers: true,
        width:300,
        striped: true,
        title:"已购产品列表",
        columns: [[
            {
                field: 'productInfos', title: '保险机构', width: 100, formatter: function (value, row, index) {
                return value ? value.name : "";
            }
            },
            {field: 'limits', title: '投保总额度', width: 100, align: 'right'}
        ]],
    })
    //清空以前的数据
    $("#editForm").form("clear");
    row["clients.clientname"] = row.clients.clientname;
    row["agencyInfos.name"] = row.agencyInfos.name;
    //数据回显:同名原则
    $("#editForm").form("load",row);
    //对话框显示
    $("#my_dialog").dialog("open");
    //修改对话框标题
    $("#my_dialog").dialog("setTitle", "编辑缴费处理单")


}
//保存
function savess(){
        var row = $("#productInfo_datagrid").datagrid("getSelected");
    var v = $('#paymentTime').datebox('getValue');
    var s = $('#method').combobox('getValue');
    console.log(s)
        $("#editForm").form("submit",{
            url:"/storages/storagesIdsStora",
            success: function(data){
                data = $.parseJSON(data);
                if(data.success){
                    //重载
                    $("#productInfo_datagrid").datagrid("reload");
                    $("#my_dialog").dialog('close');
                }
            }

        })
    $.get("/storages/storagesIdsStoraId?state=1&pay=1&id=" + row.id, function (data) {
        //重载
        $("#productInfo_datagrid").datagrid("reload");
     });
    //关闭对话框
    $("#my_dialog").dialog('close');
}
//取消
function cancel(){
    $("#my_dialog").dialog('close');
}
//刷新
function refresh() {
    //重载
    $("#productInfo_datagrid").datagrid("reload");
}
//高级查询
function querys() {
    var kw = $("#keyword").textbox("getValue");
    $("#productInfo_datagrid").datagrid("load", {
        keyword: kw
    })
}
